package propertymgmt.util;

import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;

/**
 * WindowUtils.java
 * 
 * Convenience utility class to place child Containers within a parent Container
 * 
 * @author Brian
 *
 */
public class WindowUtils {

	public static void centerWithinParent(Container child, Container parent){
		if(!(child instanceof JInternalFrame)) return;
		if(!(parent instanceof JDesktopPane)) return;

		Dimension parentSize = parent.getSize();
		Dimension mySize = child.getSize();

		int x = ((parentSize.width - mySize.width) / 2);
		int y = ((parentSize.height - mySize.height) / 2);

		child.setLocation (x, y);
		child.requestFocus();
	}
}